import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Comparator;

public class Text1 {
    public static void main(String[] args) {
        /*定义数组并存储一些女朋友对象，利用 Arrays 中的 sort 方法进行排序
        要求 1：属性有姓名、年龄、身高。
        要求 2：按照年龄的大小进行排序，年龄一样，按照身高排序，身高一样按照姓名的字母进行排序。
（姓名中不要有中文或特殊字符，会涉及到后面的知识）*/
        //创建女朋友对象
        GirlFriend gf1=new GirlFriend("xiaoshishi",18,1.67);
        GirlFriend gf2=new GirlFriend("xiaodandan",19,1.72);
        GirlFriend gf3=new GirlFriend("xiaohuihui",19,1.78);
        GirlFriend gf4=new GirlFriend("abc",19,1.78);
        //放入数组
        GirlFriend [] arr={gf1,gf2,gf3,gf4};
        //匿名内部类书写方式
        /**Arrays.sort(arr, new Comparator<GirlFriend>() {
            @Override
            public int compare(GirlFriend o1, GirlFriend o2) {
                double tmp=o1.getAge()-o2.getAge();
                tmp=tmp==0?o1.getHeight()-o2.getHeight():tmp;
                tmp=tmp==0?o1.getName().compareTo(o2.getName()):tmp;
                if(tmp>0)
                    return 1;
                else if (tmp<0) {
                    return -1;
                }
                else
                    return 0;
            }
        });*/
        //Lambda表达式书写
        Arrays.sort(arr, (o1,  o2)->{
                double tmp=o1.getAge()-o2.getAge();
                tmp=tmp==0?o1.getHeight()-o2.getHeight():tmp;
                tmp=tmp==0?o1.getName().compareTo(o2.getName()):tmp;
                if(tmp>0)
                    return 1;
                else if (tmp<0) {
                    return -1;
                }
                else
                    return 0;
            }
        );
        //展示数组内容
        System.out.println(Arrays.toString(arr));
    }
}
class GirlFriend{
    private String name;
    private int age;
    private double height;

    public GirlFriend() {
    }

    public GirlFriend(String name, int age, double height) {
        this.name = name;
        this.age = age;
        this.height = height;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return height
     */
    public double getHeight() {
        return height;
    }

    /**
     * 设置
     * @param height
     */
    public void setHeight(double height) {
        this.height = height;
    }

    public String toString() {
        return "GirlFriend{name = " + name + ", age = " + age + ", height = " + height + "}";
    }
}
